/**
 * 
 */
package daos;

import model.ClassCourse;
import model.Course;
import model.StudentClass;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.transaction.annotation.Transactional;

public class ClassCourseDAOImpl implements ClassCourseDAO {
	private SessionFactory sessionFactory;
	
	
	@Transactional
	public void save(ClassCourse classCourse) {
		Session session = sessionFactory.getCurrentSession();
		session.saveOrUpdate(classCourse);
	}
	
	@Transactional	
	public List<ClassCourse> findAllClassCourses() {
		Session session = sessionFactory.getCurrentSession();
		Query query = session.createQuery("from ClassCourse");
		return query.list();		
	}
	@Transactional
	public ClassCourse getClassCourse(int classCourseID){
		Session session = sessionFactory.getCurrentSession();
		return (ClassCourse)session.get(ClassCourse.class, classCourseID);
	}
	@Transactional
	public void delete(ClassCourse classCourse){
		Session session = sessionFactory.getCurrentSession();
		session.delete(classCourse);
	}
	@Transactional
	public List<ClassCourse> findAllClassCoursesByClass(StudentClass studentClass){
		Session session = sessionFactory.getCurrentSession();
		Query query = session.createQuery("from ClassCourse c where studentClass=:studentClass");
		query.setParameter("studentClass", studentClass);
		return query.list();
	}
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
}